package com.open.capacity.paper.controller;

import com.open.capacity.common.model.RateType;
import com.open.capacity.common.web.Result;
import com.open.capacity.paper.service.RateTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/rateType")
@Api(tags = "评分类型")
public class RateTypeController {
    @Autowired
    RateTypeService rateTypeService;

    @GetMapping("/getRateTypeList")
    @ApiOperation(value = "获取所有评分类型")
    public Result getRateTypeList() {
        return Result.succeed(rateTypeService.getRateTypeList(), "success");
    }

    @GetMapping("/getRateType")
    @ApiOperation(value = "根据id获取评分类型")
    @ApiImplicitParam(name = "rtcode", value = "评分类型code", paramType = "Integer", dataType = "json")
    public Result getRateType(String rtcode) {
        return Result.succeed(rateTypeService.getRateType(rtcode), "success");
    }

    @PostMapping("/addRateType")
    @ApiOperation(value = "添加评分类型")
    @ApiImplicitParam(name = "rateType", value = "评分类型实体类", paramType = "body", dataType = "RateType")
    public Result addRateType(@RequestBody RateType rateType) {
        if (rateTypeService.addRateType(rateType) > 0)
            return Result.succeed("添加成功");
        return Result.failed("添加失败");
    }

    @PostMapping("/updateRateType")
    @ApiOperation(value = "修改评分类型")
    @ApiImplicitParam(name = "rateType", value = "评分类型实体类", paramType = "body", dataType = "RateType")
    public Result updateRateType(@RequestBody RateType rateType) {
        if (rateTypeService.updateRateType(rateType) > 0)
            return Result.succeed("修改成功！");
        return Result.failed("修改失败");
    }

    @GetMapping("/deleteRateType")
    @ApiOperation(value = "删除评分类型")
    @ApiImplicitParam(name = "rttpid", value = "评分类型id", paramType = "Integer", dataType = "json")
    public Result deleteRateType(Integer rttpid) {
        if (rateTypeService.deleteRateType(rttpid) > 0)
            return Result.succeed("删除成功");
        return Result.failed("删除失败");
    }
}
